<?php

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/app/service/Rsa.php'; // 确保路径正确

use App\Service\Rsa;
use phpseclib3\Crypt\PublicKeyLoader;

$keyStr = file_get_contents(__DIR__ . '/key/rsa.pem');
// 从文件加载公钥
$publicKey = PublicKeyLoader::load($keyStr);

// 模拟原始数据
$data = "Hello, Workerman!";

// 使用phpseclib3的RSA加密数据
$encryptedData = $publicKey->encrypt($data);
echo "Encrypted (Base64): " . base64_encode($encryptedData) . "\n";

$prkeystr = file_get_contents(__DIR__ . '/key/rsa.key');
// 加载私钥
$privateKey = PublicKeyLoader::load($prkeystr);

// 使用phpseclib3的RSA解密数据
$decryptedData = $privateKey->decrypt($encryptedData);
echo "Decrypted: " . $decryptedData . "\n";
